<?php
namespace Admin\Controller;
class LinkController extends CommonController
{
    var $link;

    function __construct()
    {
        parent::__construct();
        $this->link = M('Link');
        $links = $this->link->select();
        $this->assign('links', $links);
    }

    function index()
    {
        $links = $this->link->order('sort_order')->select();
        $this->assign('links', $links);
        $this->display();

    }

    function store()
    {
        $this->link->create();
        $this->link->add();
        $this->success('新增成功', U('Link/index'));
    }

    function update()
    {
        $this->link->create();
        $this->link->save();
        //dump($_POST);
        $this->success('修改成功',U('index'));
    }
    function destroy(){
        $id=I("get.id");
        $this->link->where("id=$id")->delete();
        $this->success('删除成功',U('Link/index'));

    }
    function destroy_checked()
    {
        $delete_ids=I("post.delete_ids");
       foreach($delete_ids as $d){
        $this->link->where("id=$d")->delete();}
        $this->success('删除成功',U('Link/index'));

    }
    function sort_link()
    {
        $ids=I("post.ids");
        $sort_order = I("post.sort_order");

        
        foreach($ids as $key=>$i) {


            $this->link->where("id=$i")->setField('sort_order', $sort_order["$key"]);
            
        }
        $this->success('排序成功',U('Link/index'));
    }
}